<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>particles.js</title>
  <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
  <meta name="author" content="Vincent Garreau" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link rel="stylesheet" media="screen" href="../css/login.css">
</head>
<body>
<!-- particles.js container -->
<div id="particles-js" style="display: flex;align-items: center;justify-content: center">
</div>
<div class="login-page">
   <div class="login-content">
     <div class="login-tit">管理员登录</div>
     <div class="login-input">
       <input type="text"  id="username" name="username" required="required" placeholder="请输入用户名">
     </div>
     <div class="login-input">
      <input type="password" id="password" name="password" required="required" placeholder="请输入密码">
    </div>
    <div class="login-btn">
      <div class="login-btn-left">
        <span id="sub">登录</span>
      </div>
      <div class="login-btn-right" onClick="changeImg()">
        <img src="../images/check.png" alt="" id="picture"> 记住密码
      </div>
    </div>
   </div>
</div>


<!-- scripts -->
<script src="../js/particles.js"></script>
<script src="../js/app.js"></script>
<script type="text/javascript" src="../js/jquery.js"></script>
<script>
  function changeImg(){
    let pic = document.getElementById('picture');
    console.log(pic.src)
    if(pic.getAttribute("src",2) ==="img/check.png"){
      pic.src ="../images/checked.png"
    }else{
      pic.src ="../images/check.png"
    }
  }
</script>
</body>
</html>
<script type="text/javascript">

    $('#sub').on('click',function(e){
        {
            var username=$("#username").val();
            var password=$("#password").val();
            $.ajax({
                url:'/admin/login',
                type:'POST',
                data:{'username':username,'password':password},
                success:function (data) {
                    if(data=="0")
                    {
                        alert("用户名或者密码错误")
                    }
                    else {
                        window.location.replace("adminMain")
                    }
                },
                error:function () {
                    alert("ajax请求失败")
                }
            })
        }
    })
    // })
</script>